package com.wkbb.basic.controller.open;

/**
 * @author dengjingyuan
 * @date 2019-08-30 14:23
 */

import com.wkbb.basic.mapper.ClassInfoMapper;
import com.wkbb.basic.mapper.OrganizationMapper;
import com.wkbb.basic.mapper.UserMapper;
import com.wkbb.common.dto.basic.ClassInfo;
import com.wkbb.basic.model.Organization;
import com.wkbb.basic.model.User;
import com.wkbb.basic.service.DataChangeService;
import com.wkbb.common.constants.VersionConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.ClassInfoDto;
import com.wkbb.common.dto.basic.OrganizationDto;
import com.wkbb.common.dto.basic.UserDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 智慧校园数据迁移模块
 */
@RestController
@Api(description = "智慧校园数据迁移模块")
@RequestMapping("/excel/{apiVersion}/open")
@Slf4j
public class DataChangeController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private OrganizationMapper organizationMapper;

    @Autowired
    private ClassInfoMapper classInfoMapper;

    @Autowired
    private DataChangeService dataChangeService;

    @ApiOperation(value = "2.0用户ID转化")
    @RequestMapping(value = "/getUserIdbyOldUserId", method = RequestMethod.GET)
    public ResultDTO<UserDto> getUserIdbyOldUserId(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "老系统用户ID", required = true) @RequestParam(name = "oldUserId", required = true) Long oldUserId )
    {
        UserDto userDto=new UserDto();
        User user=userMapper.getNewUserByOld(oldUserId);
        if(null!=user){
            BeanUtils.copyProperties(user, userDto);
        }
        return new ResultDTO<UserDto>(userDto);
    }


    @ApiOperation(value = "2.0组织ID转化")
    @RequestMapping(value = "/getOrgIdbyOldOrgId", method = RequestMethod.GET)
    public ResultDTO<OrganizationDto> getOrgIdbyOldOrgId(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "老系统组织ID", required = true) @RequestParam(name = "oldOrgId", required = true) Long oldOrgId )
    {
        OrganizationDto organizationDto=new OrganizationDto();
        Organization organization=organizationMapper.getNewOrgByOld(oldOrgId);
        if(null!=organization){
            BeanUtils.copyProperties(organization,organizationDto);
        }
        return new ResultDTO<OrganizationDto>(organizationDto);
    }

    @ApiOperation(value = "2.0班级ID转化")
    @RequestMapping(value = "/getClassIdbyOldClassId", method = RequestMethod.GET)
    public ResultDTO<ClassInfoDto> getClassIdbyOldClassId(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "老系统班级ID", required = true) @RequestParam(name = "oldClassId", required = true) Long oldClassId )
    {
        ClassInfoDto classInfoDto=new ClassInfoDto();
        ClassInfo classInfo=classInfoMapper.getNewClassByOld(oldClassId);
        if(null!=classInfo){
            BeanUtils.copyProperties(classInfo,classInfoDto);
        }
        return new ResultDTO<ClassInfoDto>(classInfoDto);
    }

    @ApiOperation(value = "获取智慧校园所有组织")
    @RequestMapping(value = "/getWitOrganizationList", method = RequestMethod.GET)
    public ResultDTO<Object> getWitOrganizationList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧校园学校ID（仅创建者可见)", required = true, defaultValue = "ao57ZAd4NKsdone") @RequestParam(value = "objectId", required = true) String objectId)
    {
        log.info("***********DataChangeController.getWitOrganization******apiVersion:{}", apiVersion);
        dataChangeService.getWitOrganizationList(objectId);
        return new ResultDTO<>();
    }


    @ApiOperation(value = "获取智慧校园组织信息")
    @RequestMapping(value = "/getWitOrganizationInfo", method = RequestMethod.GET)
    public ResultDTO<Object> getWitOrganizationInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧校园学校ID（仅创建者可见)", required = true, defaultValue = "ao57ZAd4NKsdone") @RequestParam(value = "objectId", required = true) String objectId)
    {
        log.info("***********DataChangeController.getWitOrganizationInfo******apiVersion:{}", apiVersion);
        dataChangeService.getWitOrganizationInfo(objectId);
        return new ResultDTO<>();
    }

    @ApiOperation(value = "获取智慧校园学校信息")
    @RequestMapping(value = "/getWitSchoolInfo", method = RequestMethod.GET)
    public ResultDTO<Object> getWitSchoolInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧校园学校ID（仅创建者可见)", required = true, defaultValue = "ao57ZAd4NKsdone") @RequestParam(value = "objectId", required = true) String objectId)
    {
        log.info("***********DataChangeController.getWitSchoolInfo******apiVersion:{}", apiVersion);
        dataChangeService.getWitSchoolInfo(objectId);
        return new ResultDTO<>();
    }

    @ApiOperation(value = "获取智慧校园用户信息列表")
    @RequestMapping(value = "/getWitUserInfoList", method = RequestMethod.GET)
    public ResultDTO<Object> getWitUserInfoList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧校园学校ID（仅创建者可见)", required = true, defaultValue = "ao57ZAd4NKsdone") @RequestParam(value = "objectId", required = true) String objectId,
            @ApiParam(value = "智慧校园	组织架构ID", required = true, defaultValue = "m86wLwI2958done") @RequestParam(value = "departId", required = true) String departId,
            @ApiParam(value = "用户类型。（1-学生；2-老师；4-校友；5-退休老师；6-其他）", required = true) @RequestParam(value = "userType", required = true) Short userType,
            @ApiParam(value = "组织架构level。如：6-学生班级", required = true, defaultValue = "1") @RequestParam(value = "level", required = true) Short level
            )
    {
        log.info("***********DataChangeController.getWitSchoolInfo******apiVersion:{},objectId:{},userType:{},level:{},departId:{}", apiVersion,objectId,userType,level,departId);
        dataChangeService.getWitUserInfoList(objectId,userType,level,departId);
        return new ResultDTO<>();
    }

    @ApiOperation(value = "获取智慧校园单个用户信息")
    @RequestMapping(value = "/getWitUserInfo", method = RequestMethod.GET)
    public ResultDTO<Object> getWitUserInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧校园学校ID（仅创建者可见)", required = true, defaultValue = "ao57ZAd4NKsdone") @RequestParam(value = "objectId", required = true) String objectId,
            @ApiParam(value = "智慧校园用户id", required = true, defaultValue = "ao57ZAd4NKsdone") @RequestParam(value = "userid", required = true) String userid
    )
    {
        log.info("***********DataChangeController.getWitSchoolInfo******apiVersion:{},userid:{}", apiVersion,userid);
        dataChangeService.getWitUserInfo(objectId,userid);
        return new ResultDTO<>();
    }

}
